﻿namespace hedefgrup.graphicsLibrary
{
    using System;
    using System.Drawing;
    using System.Globalization;

    public class questionReportGraphic : graphic
    {
        private CultureInfo english = CultureInfo.GetCultureInfo("en-US");

        public override Bitmap generateImage()
        {
            int num5;
            Bitmap image = new Bitmap(templates.questionReportGraphicTemplate);
            Graphics graphics = Graphics.FromImage(image);
            int num = 0;
            int num2 = (base.yMaximumValue - base.yMinimumValue) / base.yInterval;
            for (int i = base.yMaximumValue; i >= base.yMinimumValue; i -= base.yInterval)
            {
                float num4 = 48f + (num++ * (212f / ((float) num2)));
                SizeF ef = graphics.MeasureString(i.ToString(), base.yAxisFont);
                graphics.DrawString(i.ToString(), base.yAxisFont, Brushes.Black, new PointF(40f - ef.Width, num4));
                num4 += 5f;
                graphics.DrawLine(Pens.Black, 41f, num4, 43f, num4);
                if ((num > 1) && (num <= num2))
                {
                    graphics.DrawLine(Pens.White, 45f, num4, 481f, num4);
                }
            }
            for (num5 = 0; num5 < base.mapNameLines.Length; num5++)
            {
                graphics.DrawString(base.mapNameLines[num5], base.mapNameFont, Brushes.Black, new PointF(258f - (graphics.MeasureString(base.mapNameLines[num5], base.mapNameFont).Width / 2f), (float) (10 + (num5 * 20))));
            }
            float num6 = 438f / ((float) base.xLabels.Length);
            for (num5 = 0; num5 < base.xLabels.Length; num5++)
            {
                float num7 = 44f + (num5 * num6);
                float num8 = 44f + ((num5 + 1) * num6);
                graphics.DrawLine(Pens.Black, num7, 266f, num7, 267f);
                if (num5 == (base.xLabels.Length - 1))
                {
                    graphics.DrawLine(Pens.Black, num8, 266f, num8, 267f);
                }
                SizeF ef2 = graphics.MeasureString(base.xLabels[num5], base.xLabelFont);
                graphics.DrawString(base.xLabels[num5], base.xLabelFont, Brushes.Black, (float) (((num7 + num8) - ef2.Width) / 2f), (float) 272f);
                float num9 = (base.yValues[num5] - base.yMinimumValue) / ((float) (base.yMaximumValue - base.yMinimumValue));
                float num10 = 0f;
                if (num5 < (base.xLabels.Length - 1))
                {
                    num10 = (base.yValues[num5 + 1] - base.yMinimumValue) / ((float) (base.yMaximumValue - base.yMinimumValue));
                }
                num9 = 265f - (212f * num9);
                num10 = 265f - (212f * num10);
                PointF tf = new PointF((num7 + num8) / 2f, num9);
                PointF tf2 = new PointF(((num7 + num8) + (2f * num6)) / 2f, num10);
                graphics.FillRectangle(Brushes.Red, (float) (tf.X - 3f), (float) (tf.Y - 3f), (float) 6f, (float) 6f);
                if (num5 < (base.xLabels.Length - 1))
                {
                    graphics.DrawLine(Pens.Red, tf, tf2);
                }
                graphics.FillRectangle(Brushes.Yellow, (float) (((num7 + num8) / 2f) + 5f), (float) (num9 - 9f), (float) 28f, (float) 15f);
                graphics.DrawRectangle(Pens.Black, (float) (((num7 + num8) / 2f) + 5f), (float) (num9 - 9f), (float) 28f, (float) 15f);
                graphics.DrawString(base.yValues[num5].ToString("#.0", this.english), base.xLabelFont, Brushes.Black, (float) (((num7 + num8) / 2f) + 7f), (float) (num9 - 6f));
            }
            return image;
        }
    }
}

